package k2_oop.p9_collection.demo17;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;

public class RepeatNum {

    /**
     *
     * @param nums
     * @return
     */
    public boolean method1(int[] nums){
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i+1; j < nums.length ; j++) {
                if (nums[i]==nums[j]) {
                    return true;
                }

            }
        }
        return false;
    }

    /**
     *
     * @param nums
     * @return
     */
    public boolean method2(int[] nums){

        Set<Integer> numSet = new HashSet<>();

        for (int num : nums) {
            if (!numSet.add(num)) {
                return true;
            }
        }

        return false;

    }

    public static void main(String[] args) {

        RepeatNum repeatNum = new RepeatNum();

        int[] nums = {1,2,3,1};

        boolean boo = repeatNum.method2(nums);

        if(boo){
            System.out.println("有重复元素");
        }else{
            System.out.println("没有重复元素");
        }

    }
}
